home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / java / net / ServerSocket.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  3.0 KB  |  117 lines

  1. package java.net;
  2.  
  3. import java.io.FileDescriptor;
  4. import java.io.IOException;
  5.  
  6. public class ServerSocket {
  7.    private SocketImpl impl;
  8.    private static SocketImplFactory factory;
  9.  
  10.    private ServerSocket() throws IOException {
  11.       this.impl = this.createSocketImpl();
  12.    }
  13.  
  14.    private SocketImpl createSocketImpl() {
  15.       return (SocketImpl)(factory != null ? factory.createSocketImpl() : new PlainSocketImpl());
  16.    }
  17.  
  18.    public ServerSocket(int var1) throws IOException {
  19.       this(var1, 50, (InetAddress)null);
  20.    }
  21.  
  22.    public ServerSocket(int var1, int var2) throws IOException {
  23.       this(var1, var2, (InetAddress)null);
  24.    }
  25.  
  26.    public ServerSocket(int var1, int var2, InetAddress var3) throws IOException {
  27.       this();
  28.       if (var1 >= 0 && var1 <= 65535) {
  29.          try {
  30.             SecurityManager var4 = System.getSecurityManager();
  31.             if (var4 != null) {
  32.                var4.checkListen(var1);
  33.             }
  34.  
  35.             this.impl.create(true);
  36.             if (var3 == null) {
  37.                var3 = InetAddress.anyLocalAddress;
  38.             }
  39.  
  40.             System.getSecurityManager().checkListen(var1);
  41.             this.impl.bind(var3, var1);
  42.             this.impl.listen(var2);
  43.          } catch (SecurityException var5) {
  44.             this.impl.close();
  45.             throw var5;
  46.          } catch (IOException var6) {
  47.             this.impl.close();
  48.             throw var6;
  49.          }
  50.       } else {
  51.          throw new IllegalArgumentException("Port value out of range: " + var1);
  52.       }
  53.    }
  54.  
  55.    public InetAddress getInetAddress() {
  56.       return this.impl.getInetAddress();
  57.    }
  58.  
  59.    public int getLocalPort() {
  60.       return this.impl.getLocalPort();
  61.    }
  62.  
  63.    public Socket accept() throws IOException {
  64.       Socket var1 = new Socket();
  65.       this.implAccept(var1);
  66.       return var1;
  67.    }
  68.  
  69.    protected final void implAccept(Socket var1) throws IOException {
  70.       try {
  71.          var1.impl.address = new InetAddress();
  72.          var1.impl.fd = new FileDescriptor();
  73.          this.impl.accept(var1.impl);
  74.          SecurityManager var2 = System.getSecurityManager();
  75.          if (var2 != null) {
  76.             var2.checkAccept(var1.getInetAddress().getHostAddress(), var1.getPort());
  77.          }
  78.       } catch (IOException var3) {
  79.          var1.close();
  80.          throw var3;
  81.       } catch (SecurityException var4) {
  82.          var1.close();
  83.          throw var4;
  84.       }
  85.    }
  86.  
  87.    public void close() throws IOException {
  88.       this.impl.close();
  89.    }
  90.  
  91.    public synchronized void setSoTimeout(int var1) throws SocketException {
  92.       this.impl.setOption(4102, new Integer(var1));
  93.    }
  94.  
  95.    public synchronized int getSoTimeout() throws IOException {
  96.       Object var1 = this.impl.getOption(4102);
  97.       return var1 instanceof Integer ? (Integer)var1 : 0;
  98.    }
  99.  
  100.    public String toString() {
  101.       return "ServerSocket[addr=" + this.impl.getInetAddress() + ",port=" + this.impl.getPort() + ",localport=" + this.impl.getLocalPort() + "]";
  102.    }
  103.  
  104.    public static synchronized void setSocketFactory(SocketImplFactory var0) throws IOException {
  105.       if (factory != null) {
  106.          throw new SocketException("factory already defined");
  107.       } else {
  108.          SecurityManager var1 = System.getSecurityManager();
  109.          if (var1 != null) {
  110.             var1.checkSetFactory();
  111.          }
  112.  
  113.          factory = var0;
  114.       }
  115.    }
  116. }
  117.